package cn.silver.framework.mybatis.domain;

import cn.silver.framework.core.utils.StringUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author zhouxiaobo
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "TreeEntity", description = "树结构实体")
public class TreeEntity extends BusEntity {

    @JsonIgnore
    @Schema(title = "默认根节点")
    public static final String ROOT_NODE = "0";

    @Schema(title = "上级节点")
    private String pid;

    @Schema(title = "节点编码")
    private String node;

    @Override
    public void preInsert() {
        super.preInsert();
        if (StringUtils.isBlank(this.pid)) {
            this.pid = ROOT_NODE;
        }
    }

}
